{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Apply Bitwise Operations to Make Strings Equal"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #bit-manipulation #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #位运算 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: makeStringsEqual"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #执行逐位运算使字符串相等"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个下标从 <strong>0</strong> 开始的 <strong>二元</strong> 字符串 <code>s</code> 和 <code>target</code> ，两个字符串的长度均为 <code>n</code> 。你可以对 <code>s</code> 执行下述操作 <strong>任意</strong> 次：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>选择两个 <strong>不同</strong> 的下标 <code>i</code> 和 <code>j</code> ，其中 <code>0 &lt;= i, j &lt; n</code> 。</li>\n",
    "\t<li>同时，将 <code>s[i]</code> 替换为 (<code>s[i]</code> <strong>OR</strong> <code>s[j]</code>) ，<code>s[j]</code> 替换为 (<code>s[i]</code> <strong>XOR</strong> <code>s[j]</code>) 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>例如，如果 <code>s = \"0110\"</code> ，你可以选择 <code>i = 0</code> 和 <code>j = 2</code>，然后同时将 <code>s[0]</code> 替换为 (<code>s[0]</code> <strong>OR</strong> <code>s[2]</code> = <code>0</code> <strong>OR</strong> <code>1</code> = <code>1</code>)，并将 <code>s[2]</code> 替换为 (<code>s[0]</code> <strong>XOR</strong> <code>s[2]</code> = <code>0</code> <strong>XOR</strong> <code>1</code> = <code>1</code>)，最终得到 <code>s = \"1110\"</code> 。</p>\n",
    "\n",
    "<p>如果可以使 <code>s</code> 等于 <code>target</code> ，返回 <code>true</code> ，否则，返回 <code>false</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>s = \"1010\", target = \"0110\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>可以执行下述操作：\n",
    "- 选择 i = 2 和 j = 0 ，得到 s = \"<em><strong>0</strong></em>0<em><strong>1</strong></em>0\".\n",
    "- 选择 i = 2 和 j = 1 ，得到 s = \"0<em><strong>11</strong></em>0\".\n",
    "可以使 s 等于 target ，返回 true 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>s = \"11\", target = \"00\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>执行任意次操作都无法使 s 等于 target 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>n == s.length == target.length</code></li>\n",
    "\t<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>\n",
    "\t<li><code>s</code> 和 <code>target</code> 仅由数字 <code>0</code> 和 <code>1</code> 组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [apply-bitwise-operations-to-make-strings-equal](https://leetcode.cn/problems/apply-bitwise-operations-to-make-strings-equal/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [apply-bitwise-operations-to-make-strings-equal](https://leetcode.cn/problems/apply-bitwise-operations-to-make-strings-equal/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"1010\"\\n\"0110\"', '\"11\"\\n\"00\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        '''\n",
    "        根据题意，对数对(i, j)执行一次操作后，可能的变化是：\n",
    "        11→10，01→11，10→11， 00→00\n",
    "        由于(i, j)的位置是自己选定的，因此其实11可以变为10也可以变为01，故而11，10，01是可以互转的，但与00之间不能实现互转\n",
    "        执行任意次该操作，可以实现的效果是：只要有一位为1，就可以把任意位的0都置为1；可以将任意位的1为0，但至少会剩下一位1\n",
    "        因此只需要根据s和target中是否均有1进行判断\n",
    "        '''\n",
    "\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        # cntS = Counter(s)\n",
    "        # cntT = Counter(target)\n",
    "        # if cntS['1'] == 0 and cntT['1'] > 0:\n",
    "        #     return False\n",
    "        # if cntS['0'] == cntT['0'] or cntS['0'] > cntT['0']:\n",
    "        #     return True\n",
    "        # if cntS['0'] < cntT['0'] and cntS['1']>cntT['0']-cntS['0']:\n",
    "        #     return True\n",
    "        # return False\n",
    "        return ('1' in s) == ('1' in target)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        cntS = Counter(s)\n",
    "        cntT = Counter(target)\n",
    "        if cntS['1'] == 0 and cntT['1'] > 0:\n",
    "            return False\n",
    "        if cntS['0'] == cntT['0'] or cntS['0'] > cntT['0']:\n",
    "            return True\n",
    "        if cntS['0'] < cntT['0'] and cntS['1']>cntT['0']-cntS['0']:\n",
    "            return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        sums = '1' in s\n",
    "        sumt = '1' in target\n",
    "        if (sumt and sums) or (sums==sumt):\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        \n",
    "        return False if ('1' not in s) ^ ('1' not in target) else True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return s.count('1') >= 1 and target.count('1') >= 1 or (s == target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, t: str) -> bool:\n",
    "        if s==t:\n",
    "            return True\n",
    "        if '1' not in s:\n",
    "            return False\n",
    "        if '1' in t:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        '''\n",
    "        根据题意，对数对(i, j)执行一次操作后，可能的变化是：\n",
    "        11→10，01→11，10→11， 00→00\n",
    "        由于(i, j)的位置是自己选定的，因此其实11可以变为10也可以变为01，故而11，10，01是可以互转的，但与00之间不能实现互转\n",
    "        执行任意次该操作，可以实现的效果是：只要有一位为1，就可以把任意位的0都置为1；可以将任意位的1为0，但至少会剩下一位1\n",
    "        因此只需要根据s和target中是否均有1进行判断\n",
    "        '''\n",
    "\n",
    "        if s == target:         #两者均为全0\n",
    "            return True\n",
    "        S = False\n",
    "        T = False\n",
    "        for i in s:\n",
    "            if int(i) == 1:\n",
    "                S = True\n",
    "                break\n",
    "        for j in target:\n",
    "            if int(j) == 1:\n",
    "                T = True\n",
    "                break\n",
    "        return S and T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, t: str) -> bool:\n",
    "        \"\"\"\n",
    "            s == t \n",
    "            s[i] or= s[j] \n",
    "            s[j] xor= s[i]\n",
    "        \"\"\"\n",
    "\n",
    "        return ('1' in s) == ('1' in t)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return s.count('1') >= 1 and target.count('1') >= 1 or (s == target)\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        sums = s.count('1')\n",
    "        sumt = target.count('1')\n",
    "        if (sumt and sums) or (sums==sumt):\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        # 统计两个字符串是否同时有 '1' 或同时没有 '1'\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        cnt_s = Counter(s)\n",
    "        cnt_t = Counter(target)\n",
    "        one_s = cnt_s['1']\n",
    "        one_t = cnt_t['1']\n",
    "        if one_s==one_t: return True\n",
    "        if one_s>one_t: return one_t>=1\n",
    "        return one_s>=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        n = len(s)\n",
    "        cnt1 = s.count('1')\n",
    "        cnt0 = n - cnt1\n",
    "        if s == target:\n",
    "            return True\n",
    "        return '1' in s and '1' in target\n",
    "        # for i in range(n):\n",
    "        #     if s[i] != target[i]:\n",
    "        #         if s[i] == '1':\n",
    "        #             if cnt1 > 1:\n",
    "        #                 cnt1 -= 1\n",
    "        #             else:\n",
    "        #                 return False\n",
    "        #         else:\n",
    "        #             if cnt1 > 0:\n",
    "        #                 cnt1 += 1\n",
    "        #             else:\n",
    "        #                 return False\n",
    "        # return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        a = s.count('1')\n",
    "        b = target.count('1')\n",
    "        if a == 0 and b != 0: return False\n",
    "        if b == 0 and a != 0: return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "\n",
    "        return not bool(int(s.count('1') != 0) ^ int(target.count('1') != 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        cnt_1 = 0\n",
    "        for i in s:\n",
    "            if i == '1':\n",
    "                cnt_1 += 1\n",
    "        for x, y in zip(s, target):\n",
    "            if x != y:\n",
    "                if x == '0':\n",
    "                    if cnt_1 > 0:\n",
    "                        cnt_1 += 1\n",
    "                    else:\n",
    "                        return False\n",
    "        for x, y in zip(s, target):\n",
    "            if x != y:\n",
    "                if x == '1':\n",
    "                    if cnt_1 > 1:\n",
    "                        cnt_1 -= 1\n",
    "                    else:\n",
    "                        return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        cs = Counter(s)\n",
    "        ct = Counter(target)\n",
    "        # print(cs, ct)\n",
    "        if cs['1'] > 0 and ct['1'] > 0:\n",
    "            # print(\"y\")\n",
    "            return True\n",
    "        elif cs['1'] == 0 and ct['1'] == 0:\n",
    "            # print(\"x\")\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        cnt1,cnt2=Counter(s),Counter(target)\n",
    "        #规律：每两个1可以减少一个1,01组合可以变成01 10或者11，但变不成00，00组合只能变为00\n",
    "        if cnt1['1']==0 and cnt2['1']!=0:#全是00组合\n",
    "            return False\n",
    "        if cnt1['1']!=0 and cnt2['1']==0:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        \n",
    "        return ('1' in s) == ('1' in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        if \"1\" in s and \"1\" in target:\n",
    "            return True\n",
    "        elif s == target:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        # 1 0 = 11\n",
    "        # 0 0 = 00\n",
    "        # 1 1 = 10\n",
    "        #只要01数量一致，就是可以互换的\n",
    "        #000 - 001 - 011\n",
    "        #111 - 101 - 001\n",
    "        a = s.count('1')\n",
    "        b = target.count('1')\n",
    "        if a and b:\n",
    "            return True\n",
    "        if not a and not b:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "\n",
    "        print(0 | 0, 0 ^ 0)\n",
    "        print(1 | 0, 1 ^ 0)\n",
    "        print(0 | 1, 0 ^ 1)\n",
    "        print(1 | 1, 1 ^ 1)\n",
    "\n",
    "        # 0 0 => 0 0\n",
    "        # 01 => 11 => 10\n",
    "        # 11 => 10\n",
    "\n",
    "        return (\"1\" in s) == (\"1\" in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        return (\"1\" in s) == (\"1\" in target)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        sums = s.count('1')\n",
    "        sumt = target.count('1')\n",
    "        if (sumt==0 and sums!=0) or (sums==0 and sumt!=0):\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        n = len(s)\n",
    "\n",
    "        def all_zero(lst):\n",
    "            for i in lst:\n",
    "                if i != '0':\n",
    "                    return False\n",
    "            return True\n",
    "        if all_zero(s):\n",
    "            if all_zero(target):\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        else:\n",
    "            if all_zero(target):\n",
    "                return False\n",
    "            else:\n",
    "                return True\n",
    "\n",
    "\n",
    "# 1,1 -> 1,0\n",
    "# 1,0 -> 1,1\n",
    "# 0,1 -> 1,1\n",
    "# 0,0 -> 0,0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        one = 0\n",
    "        for x in s:\n",
    "            one += x == '1'\n",
    "        zero = len(s) - one\n",
    "        \n",
    "        if zero == len(s):\n",
    "            return s == target\n",
    "        return target.count('1')  > 0\n",
    "\n",
    "                \n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        s0 = s1 = 0\n",
    "        t0 = t1 = 0\n",
    "        for i in range(len(s)):\n",
    "            if s[i] == '0':\n",
    "                s0 += 1\n",
    "            else:\n",
    "                s1 += 1\n",
    "            \n",
    "            if target[i] == '0':\n",
    "                t0 += 1\n",
    "            else:\n",
    "                t1 += 1\n",
    "\n",
    "        return (s1 > 0 and t1 > 0) or (s1 == 0 and t1 == 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        count = [0, 0]\n",
    "        for i in s:\n",
    "            if i == '1':\n",
    "                count[0] += 1\n",
    "        for i in target:\n",
    "            if i == '1':\n",
    "                count[1] += 1\n",
    "        if count[1] == 0 and (count[0] - count[1]) >= 1:\n",
    "            return False\n",
    "\n",
    "        if count[0] == 0 and count[1] > 0:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, t: str) -> bool:\n",
    "        '''\n",
    "        操作顺序是否会影响答案？\n",
    "        应该不会，1的数量会被增加和消耗\n",
    "        先增加，再消耗\n",
    "        '''\n",
    "        cnt=Counter(s)\n",
    "        if s==t: return True\n",
    "        if cnt['1']==0:return False\n",
    "        for c1,c2 in zip(s,t):\n",
    "            if c1=='0' and c2=='1':\n",
    "                cnt['1']+=1\n",
    "            if c1=='1' and c2=='0':\n",
    "                cnt['1']-=1\n",
    "        return cnt['1']>=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeStringsEqual(self, s: str, target: str) -> bool:\n",
    "        ones = diff = tOnes = 0\n",
    "        for ds, dt in zip(s, target):\n",
    "            if ds == '1':\n",
    "                ones = 1\n",
    "            if dt == '1':\n",
    "                tOnes = 1\n",
    "            if ds != dt:\n",
    "                diff = 1\n",
    "        if not diff: return True\n",
    "        return not (bool(ones) ^  bool(tOnes))\n",
    "            \n",
    "\n",
    "        # 0, 1.   1 1\n",
    "        # 0  0.   0 0\n",
    "        # 1. 1.   1 0\n",
    "        # 1  0    1 1 "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
